<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="Java基础篇（一）, Angus">
    <meta name="description" content="Java基础入门篇">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="referrer" content="no-referrer-when-downgrade">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    

    <title>Java基础篇（一） | Angus</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery-3.6.0.min.js"></script>

<meta name="generator" content="Hexo 6.1.0">
<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
<link rel="alternate" href="/atom.xml" title="Angus" type="application/atom+xml">
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>


<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">Angus</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">Angus</div>
        <div class="logo-desc">
            
            never give up!
            
        </div>
    </div>

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/Monkey-chao/Monkey-chao.github.io.git" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/Monkey-chao/Monkey-chao.github.io.git" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/22.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">Java基础篇（一）</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/Java/">
                                <span class="chip bg-color">Java</span>
                            </a>
                        
                            <a href="/tags/%E6%95%99%E7%A8%8B/">
                                <span class="chip bg-color">教程</span>
                            </a>
                        
                            <a href="/tags/%E5%9F%BA%E7%A1%80/">
                                <span class="chip bg-color">基础</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/Java%E5%9F%BA%E7%A1%80%E6%95%99%E7%A8%8B/" class="post-category">
                                Java基础教程
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2022-05-06
                </div>
                

                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-check fa-fw"></i>更新日期:&nbsp;&nbsp;
                    2022-06-18
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    10.6k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    42 分
                </div>
                

                
                    <div id="busuanzi_container_page_pv" class="info-break-policy">
                        <i class="far fa-eye fa-fw"></i>阅读次数:&nbsp;&nbsp;
                        <span id="busuanzi_value_page_pv"></span>
                    </div>
				
            </div>
        </div>
        <hr class="clearfix">

        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <h1 id="一、Java概述与基础"><a href="#一、Java概述与基础" class="headerlink" title="一、Java概述与基础"></a>一、Java概述与基础</h1><blockquote>
<p>Java语言的特点：</p>
<p>1.面向对象：</p>
<ul>
<li>三大特性：封装、继承、多态</li>
</ul>
<p>2.健壮性：</p>
<ul>
<li>吸收了C/C++语言的优点，但去掉了其影响程序健壮性的部分（如指针、内存的申请与释放等），提供了一个相对安全的内存管理和访问机制</li>
</ul>
<p>3.跨平台性：</p>
<ul>
<li>通过Java语言编写的应用程序在不同的系统平台上都可以运行。</li>
<li>原理：只需要在运行Java应用程序的操作系统上，先安装一个Java虚拟机（JVM），由JVM来负责Java程序在该系统中的运行。</li>
</ul>
<p>​	</p>
</blockquote>
<h2 id="JVM与垃圾回收机制"><a href="#JVM与垃圾回收机制" class="headerlink" title="JVM与垃圾回收机制"></a>JVM与垃圾回收机制</h2><p>核心机制-垃圾回收</p>
<ol>
<li>不再使用的内存空间应回收——垃圾回收。<ul>
<li>在C/C++等语言中，由程序员负责回收无用内存。</li>
<li>Java语言消除了程序员回收无用内存的责任；它提供一种系统级线程跟踪存储空间的分配情况，并在JVM空闲时，检查并释放那些可被释放的存储空间。</li>
</ul>
</li>
<li>垃圾回收在Java程序运行过程中自动进行，程序员无法精确控制和干扰。（可能会出现内存泄漏和内存溢出问题）</li>
</ol>
<h2 id="1-JDK-JRE-JVM"><a href="#1-JDK-JRE-JVM" class="headerlink" title="1.JDK,JRE,JVM"></a>1.JDK,JRE,JVM</h2><p>​	JDK是 Java 语言的软件开发工具包（SDK）  </p>
<p>​        JRE是运行JAVA 程序所必须的环境的集合  ,但是 jdk包含jre的</p>
<p>​        JVM 是（Java 虚拟机）的缩写 ，JVM 是实现Java 语言跨平台的法宝。   </p>
<h2 id="2-编译"><a href="#2-编译" class="headerlink" title="2.编译"></a>2.编译</h2><p>.java文件  — 源文件 （程序员读写）</p>
<p>.class文件 — 字节码文件，给虚拟机读取运行</p>
<blockquote>
<p>通过javac命令将源文件编译成字节码文件</p>
</blockquote>
<h2 id="3-类与main方法的创建"><a href="#3-类与main方法的创建" class="headerlink" title="3.类与main方法的创建"></a>3.类与main方法的创建</h2><p>main方法是程序的入口</p>
<pre class=" language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">HelloWorld</span><span class="token punctuation">{</span>

<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> rags<span class="token punctuation">)</span><span class="token punctuation">{</span>

    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="4-dos命令（了解）"><a href="#4-dos命令（了解）" class="headerlink" title="4.dos命令（了解）"></a>4.dos命令（了解）</h2><blockquote>
<p>开发仍然用图形化界面操作电脑，不适用dos命令来操作</p>
<p>dir  查看当前目录下的所有内容<br>cd .  刷新当前目录<br>cd .. 上一级目录</p>
<p>相对路径和绝对的区分：<br>绝对路径是有根目录的，盘符就是根目录<br>D:\course—绝对路径不能跨盘符<br>admin  —- 相对路径是只能相对于当前路径<br>cd 相对路径<br>cd 绝对路径<br>磁盘：切换盘符</p>
<p>del 文件名  删除文件</p>
<p>del *.txt  删除当前目录下的所有txt文件</p>
<p>del 目录 提示是否删除当前目录下的所有文件</p>
<p>echo -&gt;文件全名 创建文件</p>
<p>ipconfig 查看本机IP地址</p>
<p>ipconfig/All 查看所有  包含mac地址 （物理地址）</p>
<p>cls 清除屏幕</p>
<p>exit 退出</p>
</blockquote>
<h2 id="5-类的注意事项"><a href="#5-类的注意事项" class="headerlink" title="5.类的注意事项"></a>5.类的注意事项</h2><p>如果不用public修饰类，那么可以类名和文件名不一致</p>
<p>1 .  一个java文件中可以有多个类，但是只能有一个是public修饰</p>
<p>​	  一个java文件中 有多少个类，就产生多少个class文件</p>
<p>2 .  一个类没有main方法，可以编译，不可以运行！</p>
<p>​	  一个类中只能有一个main方法，mian方法体中也不能嵌套main方法</p>
<h2 id="6-IDEA快捷方式"><a href="#6-IDEA快捷方式" class="headerlink" title="6.IDEA快捷方式"></a>6.IDEA快捷方式</h2><blockquote>
<p>shift + shift    快速找到类<br>ctrl+f     查找要的内容<br>psvm     main方法<br>sout    输出语句<br>Ctrl+Alt +L   格式化代码</p>
<p>Ctrl + Shift + F10  运行</p>
<p>Ctrl +  /添加/删除单行注释</p>
<p>Ctrl + Shift + /添加/删除多行注释</p>
<p>Alt + Enter 自动修正</p>
<p>Ctrl + z 撤销</p>
<p>Ctrl + D 复制当前行</p>
<p>Shift + F6重命名</p>
<p>Ctrl+Alt+v  快速返回值类型</p>
<p>Alt + 鼠标左  多行编辑</p>
<p>Ctrl+Alt+z 补充代码—-查询一下</p>
<p>\反斜杠（转义符）</p>
<p>\n表示换行</p>
<p>\t表示空格</p>
</blockquote>
<h2 id="7-权限修饰符"><a href="#7-权限修饰符" class="headerlink" title="7.权限修饰符"></a>7.权限修饰符</h2><blockquote>
<p>权限就是被访问的权限</p>
<p>权限修饰符可以修饰类，修饰(成员)方法，修饰成员变量，不可修饰局部变量！</p>
<p>成员变量称为类的属性，成员方法称为类的方法<br>局部变量指的是方法体内的变量</p>
<p>private  私有化的   只能在当前类使用！<br>private 不能修饰外部类，只能修饰内部类</p>
<p>default默认的 ，不用任何词修饰就是默认的！<br>  同一个包中可以使用！</p>
<p>protected  关键字 受保护的</p>
<p>  异包&amp;继承<br>  子类中使用父类用protected修饰的内容</p>
<p>public  公开的   整个项目都可以使用</p>
</blockquote>
<blockquote>
<p>一般情况：<br>   类用public修饰<br>   成员变量用private修饰<br>   成员方法public修饰</p>
<p>   private -&gt;默认的-&gt;protected-&gt;public   </p>
<p>private可以修饰抽象内部类吗？可以！<br>private可以修饰抽象方法吗？不可以！</p>
</blockquote>
<h2 id="8-bs架构和cs架构"><a href="#8-bs架构和cs架构" class="headerlink" title="8.bs架构和cs架构"></a>8.bs架构和cs架构</h2><blockquote>
<p>bs: 不需要下载客户端，把浏览器作为客户端</p>
<p>cs: 需要下载客户端</p>
</blockquote>
<h2 id="9-程序执行的过程"><a href="#9-程序执行的过程" class="headerlink" title="9.程序执行的过程"></a>9.程序执行的过程</h2><blockquote>
<p>1.写*.java<br>2.编译，把*.java编程*.class<br>3.类加载（把class文件加载到虚拟机中）<br>4.执行程序</p>
</blockquote>
<h2 id="10-环境配置"><a href="#10-环境配置" class="headerlink" title="10.环境配置"></a>10.环境配置</h2><blockquote>
<p>JAVA_HOME:  jdk安装目录</p>
<p>path: %JAVA_HOME%\bin</p>
</blockquote>
<h2 id="11-快捷方式"><a href="#11-快捷方式" class="headerlink" title="11.快捷方式"></a>11.快捷方式</h2><blockquote>
<p>shift + shift 快速找到类<br>ctrl+f 查找要的内容<br>psvm  main方法<br>sout  输出语句<br>Ctrl+Alt +L 格式化代码</p>
<p>Ctrl + Shift + F10运行</p>
<p>Ctrl + /添加/删除单行注释</p>
<p>Ctrl + Shift + /添加/删除多行注释</p>
<p>Alt + Enter 自动修正</p>
<p>Ctrl + z 撤销</p>
<p>Ctrl + D复制当前行</p>
<p>Shift + F6重命名</p>
<p>Ctrl+Alt+v  快速返回值类型</p>
<p>Alt + 鼠标左  多行编辑</p>
<p>Ctrl+Alt+z 补充代码—-查询一下</p>
</blockquote>
<h1 id="二、基础语法"><a href="#二、基础语法" class="headerlink" title="二、基础语法"></a>二、基础语法</h1><h2 id="1-注释"><a href="#1-注释" class="headerlink" title="1. 注释"></a>1. 注释</h2><p>//单行注释</p>
<p>/**/多行注释</p>
<h2 id="2-关键字与标识符"><a href="#2-关键字与标识符" class="headerlink" title="2. 关键字与标识符"></a>2. 关键字与标识符</h2><ul>
<li><p>关键字	系统赋予特定含义的单词叫关键字，关键字特点全小写</p>
</li>
<li><p>标识符    自己命名的部分叫标识符</p>
</li>
<li><p>标识符规范：<br>   1.标识符是由字母，数字，下划线，美元符号组成<br>   2.数字不能开头<br>   3.关键字和保留字不能作为标识符<br>   4.中文和￥一般情况下可以作为标识符，但是开发禁用！</p>
</li>
<li><p>开发规范：类  –  每个单词的首字母大写</p>
</li>
</ul>
<h2 id="3-8种基本数据类型"><a href="#3-8种基本数据类型" class="headerlink" title="3. 8种基本数据类型"></a>3. 8种基本数据类型</h2><ol>
<li>整数类型 ： byte  short  int  long</li>
</ol>
<table>
<thead>
<tr>
<th align="center">整数类型</th>
<th>取值范围</th>
<th>占用字节数</th>
</tr>
</thead>
<tbody><tr>
<td align="center">byte</td>
<td>-128 到 127</td>
<td>1</td>
</tr>
<tr>
<td align="center">short</td>
<td>-2^15到2^15-1(3开头的5位数)</td>
<td>2</td>
</tr>
<tr>
<td align="center">int</td>
<td>-2^31到2^31-1(2开头的10位数)</td>
<td>4</td>
</tr>
<tr>
<td align="center">long</td>
<td>-2^63到2^63-1(9开头的19位数)</td>
<td>8</td>
</tr>
</tbody></table>
<ol start="2">
<li>小数类型(浮点类型)：double  float</li>
</ol>
<table>
<thead>
<tr>
<th>浮点数类型</th>
<th>占用字节数</th>
<th>精确度</th>
</tr>
</thead>
<tbody><tr>
<td>float</td>
<td>4</td>
<td>单精度</td>
</tr>
<tr>
<td>double</td>
<td>8</td>
<td>双精度</td>
</tr>
</tbody></table>
<ol start="3">
<li>逻辑类型: boolean</li>
</ol>
<table>
<thead>
<tr>
<th>逻辑类型</th>
<th>占用字节数</th>
<th>取值</th>
</tr>
</thead>
<tbody><tr>
<td>boolean</td>
<td>1</td>
<td>true/false</td>
</tr>
</tbody></table>
<blockquote>
<p>true和false是关键字，因为系统赋予特定的含义，并且全小写！</p>
</blockquote>
<ol start="4">
<li>字符类型: char</li>
</ol>
<table>
<thead>
<tr>
<th>字符类型</th>
<th>占用字节数</th>
<th>取值范围</th>
</tr>
</thead>
<tbody><tr>
<td>char</td>
<td>2</td>
<td>0(\u0000)到65535(\uffff)</td>
</tr>
</tbody></table>
<blockquote>
<p>char更多表示单个的字符，就是字符串中的一个！<br>如果表示的十进制数字通过ASCII码对照表能对应一个图形，就会输出图形,大写字母A的ASCII码为65、小写a为97（其余字母依次加1）</p>
</blockquote>
<pre class=" language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Test</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">char</span> c <span class="token operator">=</span> <span class="token number">97</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment" spellcheck="true">//输出结果为：a</span>
</code></pre>
<ol start="5">
<li><p>(非基本数据类型)字符串：String</p>
</li>
<li><p>精简掌握 整数用int  小数double  字符串用String</p>
</li>
</ol>
<h2 id="4-数据类型转换"><a href="#4-数据类型转换" class="headerlink" title="4. 数据类型转换"></a>4. 数据类型转换</h2><blockquote>
<p>byte,short,char之间不会相互装换，它们三者计算时首先要转换为int类型</p>
</blockquote>
<p>能够参与类型转换的数据类型只有7种<br>按照容量范围的顺序排序？ 从小到大排序<br>byte -&gt; short（char）-&gt; int -&gt; long -&gt; float -&gt; double </p>
<p>自动类型转换<br>//小容量转换大容量，不需要任何修饰不会报错！</p>
<p>强制类型转换<br>大容量转换小容量,强制要求加 强制类型转换符<br>强制转换类型2个问题：溢出、精度丢失</p>
<pre class=" language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Test</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">int</span> i<span class="token operator">=</span><span class="token number">100</span><span class="token punctuation">;</span>

        <span class="token keyword">byte</span> b <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">byte</span><span class="token punctuation">)</span>i<span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">//输出结果为：100</span>

        <span class="token keyword">char</span> c <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">char</span><span class="token punctuation">)</span>i<span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">//输出结果为：d</span>

        <span class="token keyword">short</span> s <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">short</span><span class="token punctuation">)</span>i<span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>s<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">//输出结果为：100</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>两个不同类型运算的结果是大的类型</p>
<pre class=" language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Test</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">int</span> a<span class="token operator">=</span><span class="token number">10</span><span class="token punctuation">;</span>
        <span class="token keyword">double</span> b<span class="token operator">=</span><span class="token number">20.0</span><span class="token punctuation">;</span>
        <span class="token keyword">double</span> c<span class="token operator">=</span>a<span class="token operator">+</span>b<span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">//输出结果为：30.0</span>

        <span class="token keyword">byte</span> a1<span class="token operator">=</span><span class="token number">10</span><span class="token punctuation">;</span>
        <span class="token keyword">short</span> a2<span class="token operator">=</span><span class="token number">20</span><span class="token punctuation">;</span>
        <span class="token keyword">short</span> a3<span class="token operator">=</span><span class="token punctuation">(</span><span class="token keyword">short</span><span class="token punctuation">)</span><span class="token punctuation">(</span>a1<span class="token operator">+</span>a2<span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>a3<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">//输出结果为：30</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>String类型与其他类型的+运算</p>
<pre class=" language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Test</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">char</span> c <span class="token operator">=</span> <span class="token string">'a'</span><span class="token punctuation">;</span>
        <span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
        String str <span class="token operator">=</span> <span class="token string">"Angus"</span><span class="token punctuation">;</span>

        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>c <span class="token operator">+</span> i <span class="token operator">+</span> str<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//107Angus</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>c <span class="token operator">+</span> str <span class="token operator">+</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//aAngus10</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>c <span class="token operator">+</span> <span class="token punctuation">(</span>i <span class="token operator">+</span> str<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//a10Angus</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token punctuation">(</span>c <span class="token operator">+</span> i<span class="token punctuation">)</span> <span class="token operator">+</span> str<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//107Angus</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>str <span class="token operator">+</span> i <span class="token operator">+</span> c<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//Angus10a</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="5-print和println的区别"><a href="#5-print和println的区别" class="headerlink" title="5. print和println的区别"></a>5. print和println的区别</h2><blockquote>
<p>print和println区别</p>
<p>第一个区别：<br>println是先输出内容，然后换行（Enter）</p>
<p>print 不换行一行输出</p>
<p>第二个区别：<br>println()小括号可以什么都不写</p>
<p>print()小括号必须写内容，不写就报错</p>
</blockquote>
<h2 id="6-Scanner和Random"><a href="#6-Scanner和Random" class="headerlink" title="6. Scanner和Random"></a>6. Scanner和Random</h2><p>Scanner控制台输入</p>
<pre class=" language-java"><code class="language-java"><span class="token comment" spellcheck="true">//1.创建Scanner对象---用户可以在控制台输入内容了</span>
        Scanner sc<span class="token operator">=</span><span class="token keyword">new</span> <span class="token class-name">Scanner</span><span class="token punctuation">(</span>System<span class="token punctuation">.</span>in<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">// name获取到用户输入的内容</span>
        String name <span class="token operator">=</span> sc<span class="token punctuation">.</span><span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>raondom</p>
<pre class=" language-java"><code class="language-java">Random随机数
<span class="token comment" spellcheck="true">//1.创建Random对象</span>
            Random rd <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Random</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment" spellcheck="true">//2.调用方法</span>
            <span class="token keyword">int</span> x <span class="token operator">=</span> rd<span class="token punctuation">.</span><span class="token function">nextInt</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token number">1</span><span class="token punctuation">;</span>
            System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<h2 id="7-continue，break，return"><a href="#7-continue，break，return" class="headerlink" title="7. continue，break，return"></a>7. continue，break，return</h2><blockquote>
<p>continue 跳出当次循环<br>break 结束当前整个循环  在switch语句中结束swtich语句<br>return 结束当前方法</p>
</blockquote>
<h1 id="三、运算符"><a href="#三、运算符" class="headerlink" title="三、运算符"></a>三、运算符</h1><h2 id="1-算术运算符"><a href="#1-算术运算符" class="headerlink" title="1.算术运算符"></a>1.算术运算符</h2><ul>
<li><ul>
<li><ul>
<li>/  %（ 取模 求余数）  ++ –</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="2-赋值运算符"><a href="#2-赋值运算符" class="headerlink" title="2.赋值运算符"></a>2.赋值运算符</h2><blockquote>
<p>=  +=  -=  /=  *=  %=</p>
<p>+=	  a+=2 // a=a+2</p>
<p>-=	  a-=2 // a=a-2</p>
<p>/=	  a/=2 // a=a/2</p>
<p><em>=	  a</em>=2 // a=a*2</p>
<p>%=	  a%=2 // a=a%2</p>
</blockquote>
<h2 id="3-比较运算符"><a href="#3-比较运算符" class="headerlink" title="3.比较运算符"></a>3.比较运算符</h2><blockquote>
<blockquote>
<p> &lt;  &gt;= &lt;=  == !=(不等于)</p>
</blockquote>
<p>比较运算符的结果一定是boolean类型的字面值</p>
<p>== 是比较  = 是赋值</p>
</blockquote>
<h2 id="4-逻辑运算符"><a href="#4-逻辑运算符" class="headerlink" title="4.逻辑运算符"></a>4.逻辑运算符</h2><blockquote>
<p>&amp; 并且，与    | 或者   ！非   ^异或     ||短路或     &amp;&amp;短路与</p>
<p>！	把一个条件的结果反向<br>|| 第一个条件为真则不会执行后续条件，为假则执行后续条件<br>&amp;&amp; 第一个条件为假则不会执行后续条件，为真则执行后续条件</p>
<p>比较的结果都是boolean类型的字面值</p>
</blockquote>
<h2 id="5-三目运算符"><a href="#5-三目运算符" class="headerlink" title="5.三目运算符"></a>5.三目运算符</h2><blockquote>
<p>语法： 数据类型  变量名 = 条件表达式 ？ 字面值1 ：字面值2;<br>        int      a   =   3&gt;2 ?  1 : 2;</p>
<p>含义：如果条件表达式结果是true 那么 a的值是1<br>     如果条件表达式结果是false 那么 a的值是2</p>
</blockquote>
<h1 id="四、控制语句"><a href="#四、控制语句" class="headerlink" title="四、控制语句"></a>四、控制语句</h1><h2 id="1-if语句"><a href="#1-if语句" class="headerlink" title="1.if语句"></a>1.if语句</h2><p>if语句<br>语法：if(条件表达式){if体 }</p>
<p>含义：条件成立，执行if体！条件不成立，不执行</p>
<h2 id="2-if-else语句"><a href="#2-if-else语句" class="headerlink" title="2.if-else语句"></a>2.if-else语句</h2><p>if-else语句<br>语法：if(条件表达式){if体}else{else体}</p>
<p>理解：条件成立，执行if体，条件不成立，执行else体</p>
<h2 id="3-if-else-if多分支语句"><a href="#3-if-else-if多分支语句" class="headerlink" title="3.if-else-if多分支语句"></a>3.if-else-if多分支语句</h2><ol start="3">
<li><pre><code>if-else-if多分支语句
</code></pre>
  语法：if(条1){体1}   else if(条2){体1}   else if(条3){体3}  …  else{else体 }<br>  理解：如果条1成立，执行体1，程序结束<br>   如果条1不成立，继续判断条2，如果条2还不成立，继续判断<br>   如果所有的条件都不成立，执行else体，如果期间遇到一个成立，执行那个成立的，程序就结束了</li>
</ol>
<h2 id="4-switch语句"><a href="#4-switch语句" class="headerlink" title="4.switch语句"></a>4.switch语句</h2><ol start="4">
<li><pre><code>switch语句
</code></pre>
 语法： switch(字面值){<br> case 字面值1:<br>   输出语句，变量。。。<br> break;<br>  case 字面值2:<br>   输出语句，变量。。。<br> break;<br>  case 字面值3:<br>   输出语句，变量。。。<br> break;<br> …<br> default:<br> 输出语句，其他。。。}</li>
</ol>
<p>理解：switch的字面值跟case的字面值相等，就执行case语句，如果所有的      case 跟switch的字面值不相等，执行 default语句</p>
<p>case并列： case 6: case 7: case 8:<br>                System.out.println(“夏天”);<br>                break;</p>
<h2 id="5-循环语句"><a href="#5-循环语句" class="headerlink" title="5.循环语句"></a>5.循环语句</h2><h3 id="1-for循环"><a href="#1-for循环" class="headerlink" title="[1] for循环"></a>[1] for循环</h3><p>​	</p>
<blockquote>
<p>for循环<br>语法：for(初始表达式;条件表达式;迭代语句){循环体}</p>
<p>理解：<br>     初始表达式执行，条件表达式执行，如果成立，执行循环体，执行迭代语句，再执行条件表达式<br>     初始表达式执行，条件表达式执行，如果不成立，循环结束！</p>
</blockquote>
<h3 id="2-while循环"><a href="#2-while循环" class="headerlink" title="[2] while循环"></a>[2] while循环</h3><p>​	</p>
<blockquote>
<p>while<br>语法：while(条件表达式){循环体 }<br>解释：条件成立，执行循环体，然后再判断条件，如果还成立，继续执行循环体，直到条件不成立为止！</p>
</blockquote>
<h3 id="3-do-while循环"><a href="#3-do-while循环" class="headerlink" title="[3] do-while循环"></a>[3] do-while循环</h3><blockquote>
<p>do-while<br>语法：do{循环体}while(条件表达式);<br>解释：先执行循环体，然后条件判断，如果成立继续执行循环体，然后再判断<br>直到条件表达式不成立为止！</p>
<p>三种循环 for  while  do-while<br>后期数组集合，遍历，多使用for循环<br>while循环可以使用死循环更多一些，迭代器遍历！枚举遍历！<br>do-while使用较少！</p>
<p>基础性面试题<br>while  do-while区别？</p>
<p>while循环是先判断后执行循环体<br>do-while先执行一次循环体再判断<br>如果一个程序，第一次条件就不成立，那么do-while也能执行一次循环体！</p>
</blockquote>
<p>案例代码</p>
<pre class=" language-java"><code class="language-java"> 打印<span class="token number">2</span> 到<span class="token number">100</span> 的所有素数，每行显示<span class="token number">5</span> 个素数。
 
 <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">int</span> d <span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> a <span class="token operator">=</span><span class="token number">2</span><span class="token punctuation">;</span>a<span class="token operator">&lt;=</span><span class="token number">100</span><span class="token punctuation">;</span>a<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">boolean</span> c <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
            <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> b <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span> b <span class="token operator">&lt;=</span> a <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">;</span> b<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>a <span class="token operator">%</span> b <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    c <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
                    <span class="token keyword">break</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span>c<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">print</span><span class="token punctuation">(</span>a<span class="token operator">+</span><span class="token string">"\t"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                d<span class="token operator">++</span><span class="token punctuation">;</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>d<span class="token operator">==</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                    System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    d<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>

        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</code></pre>
<pre class=" language-java"><code class="language-java">编写java 程序，打印如下的数值列表：

<span class="token number">1</span>	<span class="token number">10</span>	<span class="token number">100</span>	<span class="token number">1000</span> 
<span class="token number">2</span>	<span class="token number">20</span>	<span class="token number">200</span>	<span class="token number">2000</span>	
<span class="token number">3</span>	<span class="token number">30</span>	<span class="token number">300</span>	<span class="token number">3000</span>
<span class="token number">4</span>	<span class="token number">40</span>	<span class="token number">400</span>	<span class="token number">4000</span>
    
<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">int</span> sum<span class="token punctuation">;</span>
        <span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">int</span> j<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>j<span class="token operator">&lt;=</span><span class="token number">4</span><span class="token punctuation">;</span>j<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            sum<span class="token operator">=</span>j<span class="token punctuation">;</span>
            <span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">int</span> i<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>i<span class="token operator">&lt;=</span><span class="token number">4</span><span class="token punctuation">;</span>i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">print</span><span class="token punctuation">(</span>sum<span class="token operator">+</span><span class="token string">"\t"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                sum<span class="token operator">*=</span><span class="token number">10</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
</code></pre>
<pre class=" language-java"><code class="language-java">编写程序输出下图：

  <span class="token operator">*</span>
 <span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span>
<span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span>

<span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> rags<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">int</span> hang <span class="token operator">=</span> <span class="token number">4</span><span class="token punctuation">;</span>
        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> a <span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>a<span class="token operator">&lt;=</span><span class="token number">4</span><span class="token punctuation">;</span>a<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> c<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>c<span class="token operator">&lt;=</span>hang<span class="token operator">-</span>a<span class="token punctuation">;</span>c<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">" "</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">int</span> b <span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>b<span class="token operator">&lt;=</span>a<span class="token operator">*</span><span class="token number">2</span><span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">;</span>b<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">"*"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</code></pre>
<h1 id="五、方法-x2F-函数"><a href="#五、方法-x2F-函数" class="headerlink" title="五、方法/函数"></a>五、方法/函数</h1><h2 id="1-方法概述"><a href="#1-方法概述" class="headerlink" title="1.方法概述"></a>1.方法概述</h2><blockquote>
<p>方法的基本语法</p>
<p>方法java中又叫函数！  main方法，mian函数！</p>
<p>语法：权限修饰符  返回值  方法名（参数）{ }</p>
<p>返回值：<br>     1.无返回值类型     使用关键字void表示</p>
<p>​     2.有返回值类型<br>​       返回值类型，是任意数据类型（byte short int long float double char boolean String）<br>​       有返回值类型，必须在方法体最后一行写  return 字面值；<br>​<br>​       return 字面值；含义：结束方法之前，把字面值给出去！<br>​<br>​       字面值一定要与返回值类型匹配！<br>​<br>​       return和return 字面值;   不同，<br>​           return只有结束方法的含义！<br>​           return 字面值； 结束方法之前，把字面值给方法外部！<br>​<br>方法名：自定义标识符<br>​		类名为首字母大写，<br>​		变量名和方法名，第一个单词全小写，第二个单词开始首字母大写！</p>
<p>自定义方法跟main方法关系？</p>
<p>   main方法的方法体不能写自定义方法！— 方法之间不能嵌套</p>
<p>   自定义方法不能直接运行，可以通过main来调用执行！</p>
</blockquote>
<h2 id="2-方法重载"><a href="#2-方法重载" class="headerlink" title="2.方法重载"></a>2.方法重载</h2><pre class=" language-java"><code class="language-java">方法重载语法：
同一个类中，两个及两个以上的方法，方法名完全一致，参数列表不一致，跟其他任何内容无关！

参数列表不一致<span class="token operator">/</span>满足任一条件：
  <span class="token number">1</span><span class="token punctuation">.</span>参数个数不同
  <span class="token number">2</span><span class="token punctuation">.</span>参数类型不同
  <span class="token number">3</span><span class="token punctuation">.</span>参数的类型的顺序不同

方法重载的应用

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        Scanner sc <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Scanner</span><span class="token punctuation">(</span>System<span class="token punctuation">.</span>in<span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token function">fun</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token function">fun</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token punctuation">}</span>
    
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">int</span> <span class="token function">fun</span><span class="token punctuation">(</span><span class="token keyword">int</span> a<span class="token punctuation">,</span><span class="token keyword">int</span> b<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> a<span class="token operator">></span>b<span class="token operator">?</span> a<span class="token operator">:</span>b<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">int</span> <span class="token function">fun</span><span class="token punctuation">(</span><span class="token keyword">int</span> a<span class="token punctuation">,</span><span class="token keyword">int</span> b<span class="token punctuation">,</span><span class="token keyword">int</span> c<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token function">fun</span><span class="token punctuation">(</span><span class="token function">fun</span><span class="token punctuation">(</span>a<span class="token punctuation">,</span>b<span class="token punctuation">)</span><span class="token punctuation">,</span>c<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre>
<h2 id="3-递归"><a href="#3-递归" class="headerlink" title="3.递归"></a>3.递归</h2><pre class=" language-java"><code class="language-java">递归：方法自己调用自己（可控！）
    
递归应用

    
输出<span class="token number">1</span>到<span class="token number">10</span>
 <span class="token keyword">static</span> <span class="token keyword">int</span> i<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token function">fun</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">fun</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>i<span class="token punctuation">)</span><span class="token punctuation">;</span>
        i<span class="token operator">++</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>i<span class="token operator">&lt;=</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token function">fun</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>


通过递归计算N的阶乘

 <span class="token keyword">static</span> <span class="token keyword">int</span> sum <span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>
    <span class="token keyword">static</span> <span class="token keyword">int</span> i <span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        Scanner sc <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Scanner</span><span class="token punctuation">(</span>System<span class="token punctuation">.</span>in<span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"请输入一个数字计算阶乘"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">int</span> a <span class="token operator">=</span> sc<span class="token punctuation">.</span><span class="token function">nextInt</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token function">fun1</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">int</span> <span class="token function">fun1</span><span class="token punctuation">(</span><span class="token keyword">int</span> n<span class="token punctuation">)</span><span class="token punctuation">{</span>
        sum<span class="token operator">*=</span>i<span class="token punctuation">;</span>
        i<span class="token operator">++</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>i<span class="token operator">&lt;=</span>n<span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token function">fun1</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">return</span> sum<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre>
<h1 id="六、面向对象"><a href="#六、面向对象" class="headerlink" title="六、面向对象"></a>六、面向对象</h1><h2 id="1-面向对象概述"><a href="#1-面向对象概述" class="headerlink" title="1.面向对象概述"></a>1.面向对象概述</h2><blockquote>
<p>面向对象依赖面向过程的！<br>类是构建对象的模板<br>类是抽象的，对象具体的<br>类是大量对象的共性的抽象</p>
<p>成员变量是直接在类体中<br>局部变量在方法体中</p>
<p>局部变量不初始化，输出使用直接会报错！<br>成员变量不初始化，有默认值！</p>
<p>成员变量默认值<br>int  0<br>double 0.0<br>boolean false<br>char ‘\u0000’<br>String null </p>
</blockquote>
<h2 id="2-普通类的创建"><a href="#2-普通类的创建" class="headerlink" title="2.普通类的创建"></a>2.普通类的创建</h2><blockquote>
<p>类分两种，一种有main一种没有main！</p>
<p>有main的是要运行的，一般叫 —- 测试类！</p>
<p>没有main的，不需要运行，为了创建对象——-模板类（实体类）！</p>
<p>模板类<br>    活体，人类=属性+行为<br>    物体，手机类=属性+功能</p>
</blockquote>
<h2 id="3-通过类创建对象"><a href="#3-通过类创建对象" class="headerlink" title="3.通过类创建对象"></a>3.通过类创建对象</h2><blockquote>
<p>语法：类名  对象名 = new 类名();<br>对象名：标识符，随意取，开发规范，跟变量一样<br>new：  关键字，在堆内存中开辟一块儿新的空间！</p>
<p>总结<br>1.通过模板类能够创建对象<br>2.对对象的属性赋值<br>3.可以输出对象的属性值<br>4.可以调用对象的方法</p>
</blockquote>
<h2 id="4-类作为引用数据类型"><a href="#4-类作为引用数据类型" class="headerlink" title="4.类作为引用数据类型"></a>4.类作为引用数据类型</h2><blockquote>
<p>所有的类都可以看作是一种引用数据类型</p>
<p>Person是引用数据类型<br>把new Person()对象字面值赋值给p1,p1是Person类型<br>Person p1=new Person();</p>
<p>int基本数据类型<br>把10这个字面值数据赋值给a，a是int类型<br>int    a =10;</p>
</blockquote>
<h2 id="5-类作为成员变量"><a href="#5-类作为成员变量" class="headerlink" title="5.类作为成员变量"></a>5.类作为成员变量</h2><pre class=" language-java"><code class="language-java"><span class="token comment" spellcheck="true">//丈夫类</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Husband</span> <span class="token punctuation">{</span>
    <span class="token comment" spellcheck="true">//属性：名字  年龄  妻子</span>
    String hbdName<span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">//Wife是一种自定义的引用数据类型</span>
    Wife w<span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">//通过Wife类创建的对象都可以赋值给w,等同于Person类创建多个对象赋值给p1,p2</span>
   <span class="token comment" spellcheck="true">// Person p1=new Person();</span>
   <span class="token comment" spellcheck="true">// Person p2=new Person();</span>
<span class="token punctuation">}</span>


<span class="token comment" spellcheck="true">//妻子类</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Wife</span> <span class="token punctuation">{</span>
    String wifeName<span class="token punctuation">;</span>
<span class="token punctuation">}</span>


    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        
        Wife w1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Wife</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        w1<span class="token punctuation">.</span>wifeName<span class="token operator">=</span><span class="token string">"孙尚香"</span><span class="token punctuation">;</span>
        
        Husband h1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Husband</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
       
        h1<span class="token punctuation">.</span>hbdName<span class="token operator">=</span><span class="token string">"刘备"</span><span class="token punctuation">;</span>
        h1<span class="token punctuation">.</span>w<span class="token operator">=</span>w1<span class="token punctuation">;</span>

        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>h1<span class="token punctuation">.</span>hbdName<span class="token operator">+</span><span class="token string">"--------"</span><span class="token operator">+</span>h1<span class="token punctuation">.</span>w<span class="token punctuation">.</span>wifeName<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token punctuation">}</span>

</code></pre>
<h2 id="6-类作为参数类型"><a href="#6-类作为参数类型" class="headerlink" title="6.类作为参数类型"></a>6.类作为参数类型</h2><blockquote>
<p>任何类都是一种引用数据类型<br>   把类作为属性成员变量<br>   丈夫类和妻子类</p>
<p>   面向对象关注的是对象<br>   饲养员给熊猫喂食</p>
<p>   哪个饲养员？哪个熊猫？</p>
<p>   任何饲养员喂食任何熊猫！</p>
<p>   饲养员类  —-  属性：名字  动作：喂食<br>   熊猫类    —-属性：名字  动作：吃竹子</p>
</blockquote>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day13<span class="token punctuation">.</span>classes<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">//熊猫饲养员</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">KeeperPanda</span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> String name<span class="token punctuation">;</span>

    <span class="token keyword">public</span> String <span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> name<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setName</span><span class="token punctuation">(</span>String name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> name<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token function">KeeperPanda</span><span class="token punctuation">(</span>String name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> name<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token function">KeeperPanda</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token punctuation">}</span>

    <span class="token comment" spellcheck="true">//喂熊猫--- 喂一个具体熊猫，---喂一个熊猫对象</span>
    <span class="token comment" spellcheck="true">//具体的熊猫对象是 Panda类型</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">feed</span><span class="token punctuation">(</span>Panda panda<span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token comment" spellcheck="true">//=new Panda("盼盼");</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>name<span class="token operator">+</span><span class="token string">"喂："</span><span class="token operator">+</span>panda<span class="token punctuation">.</span><span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        panda<span class="token punctuation">.</span><span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>



<span class="token punctuation">}</span>
</code></pre>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day13<span class="token punctuation">.</span>classes<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">//熊猫类</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Panda</span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> String name<span class="token punctuation">;</span>

    <span class="token keyword">public</span> String <span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> name<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setName</span><span class="token punctuation">(</span>String name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> name<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token function">Panda</span><span class="token punctuation">(</span>String name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> name<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token function">Panda</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>name<span class="token operator">+</span><span class="token string">"吃竹子！"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day13<span class="token punctuation">.</span>classes<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Test</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        Panda p1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Panda</span><span class="token punctuation">(</span><span class="token string">"盼盼"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        KeeperPanda k1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">KeeperPanda</span><span class="token punctuation">(</span><span class="token string">"刘备"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        k1<span class="token punctuation">.</span><span class="token function">feed</span><span class="token punctuation">(</span>p1<span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="7-类作为返回值类型"><a href="#7-类作为返回值类型" class="headerlink" title="7.类作为返回值类型"></a>7.类作为返回值类型</h2><blockquote>
<p>创建对象和使用对象分离—-解耦合！<br>Person p1=new Person();<br>p1.eat();</p>
</blockquote>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day13<span class="token punctuation">.</span>classes02<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">//苹果类</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Apple</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"吃苹果。。。"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day13<span class="token punctuation">.</span>classes02<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">//苹果工厂，java中不管什么工厂都是生成对象的！---- 工具类</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">AppleFactory</span> <span class="token punctuation">{</span>

    <span class="token comment" spellcheck="true">//方法：谁调用这个方法，给它一个苹果Apple对象</span>
<span class="token keyword">public</span> <span class="token keyword">static</span> Apple <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">Apple</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>


<span class="token punctuation">}</span>
</code></pre>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day13<span class="token punctuation">.</span>classes02<span class="token punctuation">;</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Test</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        Apple a11 <span class="token operator">=</span> AppleFactory<span class="token punctuation">.</span><span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        Apple a22 <span class="token operator">=</span> AppleFactory<span class="token punctuation">.</span><span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        Apple a33 <span class="token operator">=</span> AppleFactory<span class="token punctuation">.</span><span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        a11<span class="token punctuation">.</span><span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        a22<span class="token punctuation">.</span><span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        a33<span class="token punctuation">.</span><span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="8-构造函数"><a href="#8-构造函数" class="headerlink" title="8.构造函数"></a>8.构造函数</h2><blockquote>
<p>语法：【public】类名(【参数】){}<br>构造函数，是创建对象的时候被调用的！</p>
<p>构造函数作用<br>1.创建对象依赖构造函数<br>  一个类没有手动写任何构造函数，也会有一个构造函数（默认的，隐式的，无参的），为了满足创建对象的依赖<br>  一个类如果手动写了构造函数，就不会再生成那个（默认的，隐式的，无参的）构造函数<br> 一个类如果写了有参构造，应该把无参构造也写出来！</p>
<ol start="2">
<li>给属性初始化</li>
</ol>
</blockquote>
<p>空指针异常</p>
<blockquote>
<p>NullPointerException 空指针异常<br>原因：一个变量，引用的对象是null，在堆内存不开辟空间，更没有属性和方法，这个时候，去调用就会出现 空指针异常！</p>
</blockquote>
<h2 id="9-函数-x2F-方法之间的调用"><a href="#9-函数-x2F-方法之间的调用" class="headerlink" title="9.函数/方法之间的调用"></a>9.函数/方法之间的调用</h2><blockquote>
<p>​	非静态方法既可以调用静态属性和方法也可以调用非静态属性和方法！<br>​	调用静态的属性和方法时，省略的是类名，调用非静态的属性和方法时省略的是this</p>
<p>静态方法只能调用静态属性和静态方法，省略的都是类名！</p>
<p>构造函数可以调用静态的属性和方法，也可以调用非静态的属性和方法</p>
<p>总结：非静态方法什么都能调用（构造函数除外）<br>     静态方法只能调用静态成员<br>     构造函数什么都能调用</p>
</blockquote>
<h1 id="七、对象的封装"><a href="#七、对象的封装" class="headerlink" title="七、对象的封装"></a>七、对象的封装</h1><h2 id="1-封装概述"><a href="#1-封装概述" class="headerlink" title="1.封装概述"></a>1.封装概述</h2><blockquote>
<p>面向对象三大特征：封装，继承，多态</p>
<p>封装是一种思想，课件中只是属性的封装！</p>
<p>封装理解：包装 更安全！</p>
<p>属性封装，数据更安全！</p>
<ul>
<li>为什么学习封装？</li>
</ul>
<p>用户可以随意给值，不符合实际情况的年龄也是可以赋值的，数据就无效！</p>
</blockquote>
<h2 id="2-封装步骤"><a href="#2-封装步骤" class="headerlink" title="2.封装步骤"></a>2.封装步骤</h2><blockquote>
<p>private 关键字 私有化的</p>
<p>private 可以修饰内部类，private可以修饰成员变量，private可以修饰成员方法</p>
<p>属性封装，主要使用private修饰属性–成员变量</p>
<p>private 修饰的内容，只能在当前类中使用!</p>
<p>第一步：private修饰属性（其他类不能直接操作属性）</p>
<p>第二步：提供公开的（public）设置值的方法（set方法）</p>
<p>第三步：提供公开的（public）获取属性的方法(get方法)</p>
</blockquote>
<pre class=" language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Student</span> <span class="token punctuation">{</span>
   String name<span class="token punctuation">;</span>
<span class="token keyword">private</span>   <span class="token keyword">int</span> age<span class="token punctuation">;</span>

<span class="token comment" spellcheck="true">//给age设置值！</span>
<span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setAge</span><span class="token punctuation">(</span><span class="token keyword">int</span> age<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span>age<span class="token operator">></span><span class="token number">0</span> <span class="token operator">&amp;&amp;</span> age<span class="token operator">&lt;</span><span class="token number">130</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>age<span class="token operator">=</span>age<span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token keyword">else</span> <span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>err<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"年龄设置不合理，默认年龄18！"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>age<span class="token operator">=</span><span class="token number">18</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token comment" spellcheck="true">//返回age</span>
    <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">getAge</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> age<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>


<span class="token comment" spellcheck="true">//main方法</span>

 <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        Student s1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Student</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
         s1<span class="token punctuation">.</span>name<span class="token operator">=</span><span class="token string">"张三"</span><span class="token punctuation">;</span>
         <span class="token comment" spellcheck="true">//s1.age=20;</span>
        s1<span class="token punctuation">.</span><span class="token function">setAge</span><span class="token punctuation">(</span><span class="token number">2000</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token comment" spellcheck="true">//  System.out.println("名字："+s1.name+"\t年龄："+s1.age);</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"名字："</span><span class="token operator">+</span>s1<span class="token punctuation">.</span>name<span class="token operator">+</span><span class="token string">"\t年龄："</span><span class="token operator">+</span>s1<span class="token punctuation">.</span><span class="token function">getAge</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre>
<h1 id="八、This和Static"><a href="#八、This和Static" class="headerlink" title="八、This和Static"></a>八、This和Static</h1><h2 id="1-this关键字"><a href="#1-this关键字" class="headerlink" title="1.this关键字"></a>1.this关键字</h2><blockquote>
<p>this指向<br>this 当前对象</p>
<p>类的非static方法中使用this，表示当前对象，这个方法被哪个对象调用，this就是哪个对象！</p>
<p>this可以区分成员变量和局部变量</p>
<p>this在构造函数之间的调用</p>
<p>语法：this(【实参】);  必须在第一行！</p>
<p>构造函数中没有递归，也不能相互调用，影响创建对象！</p>
<p>构造函数可以直接调用非构造函数！</p>
<p>构造函数之间调用的意义？<br>无参构造去调用有参构造可以，提高代码的重复利用率！</p>
</blockquote>
<h2 id="2-static关键字"><a href="#2-static关键字" class="headerlink" title="2.static关键字"></a>2.static关键字</h2><blockquote>
<p>public static void main(String[] args){ }</p>
<p>static 静态的</p>
<p>static可以修饰内部类（过几天再讲）</p>
<p>static可以修饰属性  ========</p>
<p>static可以修饰方法  ========</p>
<p>static可以修饰代码块  ========</p>
<p>static修饰成员变量，静态变量！<br>static修饰属性，静态属性！<br>static不能修饰局部变量<br>static修饰的内容都倾斜，在idea中！</p>
<p>结论：<br>一处设置处处设置，一处修改处处修改！<br>当遇到很多对象都有同一个属性的值，这个时候用static修饰这个属性！</p>
</blockquote>
<blockquote>
<p>static修饰方法(重点调用)<br>static修饰的方法就叫静态方法，没有static修饰的方法，叫非静态方法</p>
<p>使用工具类的方法<br>类名.静态属性/静态方法</p>
</blockquote>
<h2 id="3-static代码块"><a href="#3-static代码块" class="headerlink" title="3.static代码块"></a>3.static代码块</h2><blockquote>
<p>{ } 非静态代码块</p>
<p>static{} 静态代码块</p>
<p>除了明显的死循环，其他内容都可以写，跟方法体没什么区别<br>静态代码块儿只能调用静态的成员，非静态代码块什么都能调用</p>
<p>规律：<br>一个类中有静态代码块，非静态代码块，构造函数<br>如果创建对象，执行顺序：<br>    静态代码块先执行<br>    非静态代码块执行<br>    构造函数执行<br>如果多次创建对象，非静态代码块和构造函数执行多次，静态代码块执行一次    </p>
</blockquote>
<h2 id="4-方法区（1-7）"><a href="#4-方法区（1-7）" class="headerlink" title="4.方法区（1.7）"></a>4.方法区（1.7）</h2><blockquote>
<p>对象为空，调用静态方法和静态属性都不会出现空指针异常NullPointerException</p>
<p>类加载是遇到什么加载什么！</p>
<p>静态区：类加载时，遇到静态内容都存储到静态区！</p>
</blockquote>
<h1 id="九、继承"><a href="#九、继承" class="headerlink" title="九、继承"></a>九、继承</h1><h2 id="1-继承概述"><a href="#1-继承概述" class="headerlink" title="1.继承概述"></a>1.继承概述</h2><blockquote>
<p>继承，继承财产<br>继承是类与类直接的关系的表示<br>子类继承父类<br>父类可以有私有的内容 ，子类不可继承！<br>子类也可以有独有的方法，跟父类不一样！</p>
</blockquote>
<h2 id="2-继承的关系区分"><a href="#2-继承的关系区分" class="headerlink" title="2.继承的关系区分"></a>2.继承的关系区分</h2><blockquote>
<p>子类  继承  父类<br>Account  4个属性    CreditAccount 5个属性</p>
<p>继承的关系？ —- 从属关系</p>
<p>父类更通用（抽象），子类更具体！</p>
<p>信用卡属于银行卡的一种！   CreditAccount is  a Account!</p>
</blockquote>
<h2 id="3-继承的语法特性"><a href="#3-继承的语法特性" class="headerlink" title="3.继承的语法特性"></a>3.继承的语法特性</h2><blockquote>
<p>extends 关键字   延伸，继承</p>
<p>1.子类extends父类<br>public class Zi extends Fu {}</p>
<p>2.子类继承父类，继承父类所有的属性和方法（私有化，构造方法 除外）</p>
<p>   属性封装，要求属性必须私有化，私有化的不能继承，那么属性封装和继承存在矛盾吗？不存在，属性封装要求属性私有化的同时还要提供公开的，get和set方法，那么get和set是可以被继承的，所以继承和封装一起使用，不存在矛盾！</p>
<p>   子类所有的构造函数，都隐式的，默认的调用父类的无参构造。。。<br>   构造函数是调用关系，不是继承关系！<br>   子类不管什么构造函数运行时都会调用父类的无参构造</p>
<p>3.java中继承都是单继承，一个子类只能有一个父类<br>  单继承会让子类的功能强大缺失，弥补功能的问题，支持间接多继承！</p>
<ol start="4">
<li><p>A -&gt; B -&gt;  C -&gt;  D -&gt; E  继承缺点，耦合度过高！</p>
<p>耦合度：连系性，关联性太强！父类出问题，子类都出问题！</p>
<p>手机 耦合度高的产品</p>
<p>台式电脑 耦合度低，高内聚</p>
<p>低耦合，高内聚！</p>
</li>
</ol>
<p>5.继承分两个内容，一个是隐式继承，一个是显示继承<br>  显示继承：写extends就是显示！<br>  隐式继承：任何类都直接或者间接继承Object类！<br>          一个类没有直接继承其他类，它一定隐式继承Object类<br>          一个类显示继承了其他类，它一定间接继承Object类</p>
</blockquote>
<h2 id="4-静态内容是否能继承？"><a href="#4-静态内容是否能继承？" class="headerlink" title="4.静态内容是否能继承？"></a>4.静态内容是否能继承？</h2><pre class=" language-java"><code class="language-java">静态内容都可以继承的，但是子类和父类调用的是同一个静态内容，可以不去继承的！
<span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day12<span class="token punctuation">.</span>extends04<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Fu</span> <span class="token punctuation">{</span>
    <span class="token keyword">int</span> a<span class="token punctuation">;</span>
    <span class="token keyword">static</span> <span class="token keyword">int</span> b<span class="token punctuation">;</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">fun1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">fun2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day12<span class="token punctuation">.</span>extends04<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Zi</span> <span class="token keyword">extends</span> <span class="token class-name">Fu</span> <span class="token punctuation">{</span>
<span class="token punctuation">}</span>


<span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day12<span class="token punctuation">.</span>extends04<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TestZi</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        Zi zi <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Zi</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>zi<span class="token punctuation">.</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>
       <span class="token comment" spellcheck="true">// System.out.println(zi.b);---警告</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>Fu<span class="token punctuation">.</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>Zi<span class="token punctuation">.</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
        zi<span class="token punctuation">.</span><span class="token function">fun1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
       <span class="token comment" spellcheck="true">// zi.fun2();</span>
        Zi<span class="token punctuation">.</span><span class="token function">fun2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        Fu<span class="token punctuation">.</span><span class="token function">fun2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="5-方法的覆盖-x2F-重写"><a href="#5-方法的覆盖-x2F-重写" class="headerlink" title="5.方法的覆盖/重写"></a>5.方法的覆盖/重写</h2><pre class=" language-java"><code class="language-java">方法的重载overload
方法的重写override
为什么用方法的重写？
父类比子类更抽象的，方法也比子类更抽象，父类方法无法满足子类需求
<span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day12<span class="token punctuation">.</span>override02<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">//猴子</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Monkey</span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> String name<span class="token punctuation">;</span>

    <span class="token keyword">public</span> String <span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> name<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setName</span><span class="token punctuation">(</span>String name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> name<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token comment" spellcheck="true">//方法：</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">speak</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"猴子说猴语。。。"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>


<span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day12<span class="token punctuation">.</span>override02<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">//人类</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ChinesePeople</span> <span class="token keyword">extends</span> <span class="token class-name">Monkey</span><span class="token punctuation">{</span>
<span class="token punctuation">}</span>
</code></pre>
<p>  重写的语法</p>
<blockquote>
<p>1.权限修饰符子类要大于等于父类<br>   protected（权限小）  public(权限大)</p>
<p>2.返回值类型，子类必须和父类一致</p>
<p>3.方法名和参数类型，子类必须和父类一致</p>
<p>4.子类不能比父类抛出更多异常（第二阶段让老师演示一下！！！）</p>
<p>5.重写主要修改的是方法体！</p>
<p>Alt+Insert生成，开发！  @Override 注解==============</p>
</blockquote>
<h2 id="6-静态方法是否能重写？"><a href="#6-静态方法是否能重写？" class="headerlink" title="6.静态方法是否能重写？"></a>6.静态方法是否能重写？</h2><blockquote>
<p>静态方法不能被重写<br>使用Alt+Insert 没有重写的<br>父子都有静态方法，都是各自跟各自类绑定<br>多态可以再次证明！</p>
<p>静态方法可以被继承，但是不可以被重写！</p>
<p>重写和重载区别？</p>
<p>重载：同一个类中，两个及两个以上的方法，方法名相同，参数列表不同，跟其他无关！</p>
<p>重写：继承关系中，父类的方法，不能满足子类需求，子类需要建立在父类方法基础上改造成子类需要的方法</p>
</blockquote>
<h2 id="7-子类构造函数调用父类构造函数意义"><a href="#7-子类构造函数调用父类构造函数意义" class="headerlink" title="7.子类构造函数调用父类构造函数意义"></a>7.子类构造函数调用父类构造函数意义</h2><p> this无参调用有参提高代码的重复利用率</p>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day12<span class="token punctuation">.</span>superdemo02<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Demo</span> <span class="token punctuation">{</span>
    String name<span class="token punctuation">;</span>
    <span class="token keyword">int</span> age<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token function">Demo</span><span class="token punctuation">(</span>String name<span class="token punctuation">,</span> <span class="token keyword">int</span> age<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>name <span class="token operator">=</span> name<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>age <span class="token operator">=</span> age<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
     <span class="token comment" spellcheck="true">//属性初始化</span>
    <span class="token keyword">public</span> <span class="token function">Demo</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token comment" spellcheck="true">//        this.name="刘备";</span>
<span class="token comment" spellcheck="true">//        this.age=18;</span>
        <span class="token keyword">this</span><span class="token punctuation">(</span><span class="token string">"刘备"</span><span class="token punctuation">,</span><span class="token number">18</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>super调用父类的构造函数，提高代码的重复利用率</p>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day12<span class="token punctuation">.</span>superdemo02<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Account</span> <span class="token punctuation">{</span>
   <span class="token keyword">private</span> String acID<span class="token punctuation">;</span>
   <span class="token keyword">private</span> String username<span class="token punctuation">;</span>
   <span class="token keyword">private</span> String password<span class="token punctuation">;</span>
   <span class="token keyword">private</span> <span class="token keyword">double</span> balance<span class="token punctuation">;</span>

    <span class="token keyword">public</span> String <span class="token function">getAcID</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> acID<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setAcID</span><span class="token punctuation">(</span>String acID<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>acID <span class="token operator">=</span> acID<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> String <span class="token function">getUsername</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> username<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setUsername</span><span class="token punctuation">(</span>String username<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>username <span class="token operator">=</span> username<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> String <span class="token function">getPassword</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> password<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setPassword</span><span class="token punctuation">(</span>String password<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>password <span class="token operator">=</span> password<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">double</span> <span class="token function">getBalance</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> balance<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setBalance</span><span class="token punctuation">(</span><span class="token keyword">double</span> balance<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>balance <span class="token operator">=</span> balance<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token function">Account</span><span class="token punctuation">(</span>String acID<span class="token punctuation">,</span> String username<span class="token punctuation">,</span> String password<span class="token punctuation">,</span> <span class="token keyword">double</span> balance<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>acID <span class="token operator">=</span> acID<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>username <span class="token operator">=</span> username<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>password <span class="token operator">=</span> password<span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>balance <span class="token operator">=</span> balance<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token function">Account</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>





<span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day12<span class="token punctuation">.</span>superdemo02<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">CreditAccount</span> <span class="token keyword">extends</span> <span class="token class-name">Account</span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token keyword">int</span> score<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">getScore</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> score<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">setScore</span><span class="token punctuation">(</span><span class="token keyword">int</span> score<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>score <span class="token operator">=</span> score<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token function">CreditAccount</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token function">CreditAccount</span><span class="token punctuation">(</span>String acID<span class="token punctuation">,</span> String username<span class="token punctuation">,</span> String password<span class="token punctuation">,</span> <span class="token keyword">double</span> balance<span class="token punctuation">,</span><span class="token keyword">int</span> score<span class="token punctuation">)</span><span class="token punctuation">{</span>
<span class="token comment" spellcheck="true">//        super.setAcID(acID);</span>
<span class="token comment" spellcheck="true">//        super.setBalance(balance);</span>
<span class="token comment" spellcheck="true">//        super.setPassword(password);</span>
<span class="token comment" spellcheck="true">//        super.setUsername(username);</span>
        <span class="token keyword">super</span><span class="token punctuation">(</span>acID<span class="token punctuation">,</span>username<span class="token punctuation">,</span>password<span class="token punctuation">,</span>balance<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>score<span class="token operator">=</span>score<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>





<span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day12<span class="token punctuation">.</span>superdemo02<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Test</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        CreditAccount c <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">CreditAccount</span><span class="token punctuation">(</span><span class="token string">"21465465"</span><span class="token punctuation">,</span><span class="token string">"刘备"</span><span class="token punctuation">,</span><span class="token string">"12345"</span><span class="token punctuation">,</span><span class="token number">1000</span><span class="token punctuation">,</span><span class="token number">200</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>


Alt<span class="token operator">+</span>Insert<span class="token operator">==</span><span class="token operator">==</span>生成构造函数！
</code></pre>
<h2 id="8-继承的内容"><a href="#8-继承的内容" class="headerlink" title="8.继承的内容"></a>8.继承的内容</h2><p><img src="/1628498794395.png" alt="1628498794395"></p>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day12<span class="token punctuation">.</span>extends05<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Fu</span> <span class="token punctuation">{</span>
    <span class="token keyword">int</span> a<span class="token punctuation">;</span>
    <span class="token keyword">static</span>  <span class="token keyword">int</span> b<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">fun1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"fun1..."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">fun2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"fun2..."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day12<span class="token punctuation">.</span>extends05<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Zi</span> <span class="token keyword">extends</span> <span class="token class-name">Fu</span> <span class="token punctuation">{</span>
    <span class="token keyword">int</span> c<span class="token punctuation">;</span>
    <span class="token keyword">static</span> <span class="token keyword">int</span> d<span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">fun3</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"fun3..."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">fun4</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"fun4..."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">info</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token comment" spellcheck="true">//非静态的---------------</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token keyword">super</span><span class="token punctuation">.</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">fun1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">fun1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token function">fun1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">//静态的------------------</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token keyword">super</span><span class="token punctuation">.</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>Fu<span class="token punctuation">.</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>Zi<span class="token punctuation">.</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">fun2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">fun2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        Fu<span class="token punctuation">.</span><span class="token function">fun2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        Zi<span class="token punctuation">.</span><span class="token function">fun2</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day12<span class="token punctuation">.</span>extends05<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Test</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        Zi zi <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Zi</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        zi<span class="token punctuation">.</span>a<span class="token operator">=</span><span class="token number">50</span><span class="token punctuation">;</span>
        zi<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre>
<h1 id="十、Super"><a href="#十、Super" class="headerlink" title="十、Super"></a>十、Super</h1><pre class=" language-java"><code class="language-java"><span class="token keyword">this</span>和<span class="token keyword">super</span>对比学习

<span class="token keyword">this</span><span class="token operator">:</span>当前对象
     <span class="token keyword">this</span>在非静态方法中使用，谁调用这个方法，<span class="token keyword">this</span>就是这个对象！
     
<span class="token keyword">super</span><span class="token operator">:</span>父类特征
      <span class="token keyword">super</span>在子类的非静态方法中使用，指向父类的属性和方法！
      
 <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">fun</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">//System.out.println(super);错误的，super不是对象不能直接输出</span>
    <span class="token punctuation">}</span>      

<span class="token keyword">this</span>使用场景：
     <span class="token number">1</span><span class="token punctuation">.</span>默认使用
     <span class="token number">2</span><span class="token punctuation">.</span>有参构造对属性初始化，<span class="token keyword">this</span><span class="token punctuation">.</span>属性<span class="token operator">=</span>属性
       set方法，<span class="token keyword">this</span><span class="token punctuation">.</span>属性<span class="token operator">=</span>属性
       区分成员变量和局部变量，<span class="token keyword">this</span>不可省略！
     <span class="token number">3</span><span class="token punctuation">.</span>构造函数之间相互调用使用<span class="token keyword">this</span><span class="token punctuation">(</span>【实参】<span class="token punctuation">)</span><span class="token punctuation">;</span> 第一行
    
<span class="token keyword">super</span>使用场景：
    <span class="token number">1</span><span class="token punctuation">.</span>默认使用
    <span class="token number">2</span><span class="token punctuation">.</span><span class="token keyword">super</span><span class="token punctuation">.</span>方法（）
       如果在重写的方法中调用父类的方法，<span class="token keyword">super</span>不可省略
    
    <span class="token number">3</span><span class="token punctuation">.</span>子类调用父类构造函数<span class="token keyword">super</span><span class="token punctuation">(</span>【实参】<span class="token punctuation">)</span><span class="token punctuation">;</span>第一行
    
    子类所有的构造函数都默认的隐士的调用父类的无参构造
    
    <span class="token keyword">this</span><span class="token punctuation">(</span><span class="token punctuation">)</span>和<span class="token keyword">super</span><span class="token punctuation">(</span><span class="token punctuation">)</span>不能在同一个构造函数中使用！
    
    父类如果没有无参构造，子类所有的构造函数都必须手动调用父类的有参构造
    
</code></pre>
<h1 id="十一、多态"><a href="#十一、多态" class="headerlink" title="十一、多态"></a>十一、多态</h1><h2 id="1-多态概述"><a href="#1-多态概述" class="headerlink" title="1.多态概述"></a>1.多态概述</h2><blockquote>
<p>多态，多种形态。<br>作用，降低代码的耦合度<br>多态含义：同一个动作，在不同的环境，出现不同的结果<br>在桌面按F1,浏览器帮助中心  在word文档中，按F1，得到word的帮助中心<br>同一个方法，传递不同的参数，运行的是不同的内容！</p>
</blockquote>
<h2 id="2-多态语法"><a href="#2-多态语法" class="headerlink" title="2.多态语法"></a>2.多态语法</h2><blockquote>
<p>多态前提条件：继承  重写<br>达到多态三个条件：1.继承  2.重写  3.向上转型（自动类型转换）<br>特点：多态形式，只能调用重写的方法，执行的是子类的方法<br>     不能调用子类独有的方法！</p>
</blockquote>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day13<span class="token punctuation">.</span>polymorphic01<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">//动物类</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Animal</span> <span class="token punctuation">{</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"动物吃。。。"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day13<span class="token punctuation">.</span>polymorphic01<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Dog</span> <span class="token keyword">extends</span> <span class="token class-name">Animal</span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"狗吃骨头。。。"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token comment" spellcheck="true">//狗！</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">lookDoor</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"看门。。。"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day13<span class="token punctuation">.</span>polymorphic01<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Test</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment" spellcheck="true">//向上转型，自动类型转换</span>
        <span class="token comment" spellcheck="true">// 10是整数字面值  int类型，自动提升为double</span>
        <span class="token keyword">double</span> b<span class="token operator">=</span><span class="token number">10</span><span class="token punctuation">;</span>
        <span class="token comment" spellcheck="true">//new Dog() 对象字面值，Dog类型，自动提升为Animal</span>
        Animal d1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Dog</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        d1<span class="token punctuation">.</span><span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
       <span class="token comment" spellcheck="true">// d1.lookDoor();</span>


    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h1 id="十二、final关键字"><a href="#十二、final关键字" class="headerlink" title="十二、final关键字"></a>十二、final关键字</h1><p>面试题</p>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day14<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Fu</span> <span class="token punctuation">{</span>
    <span class="token keyword">int</span> a<span class="token operator">=</span><span class="token number">10</span><span class="token punctuation">;</span>
    <span class="token keyword">static</span> <span class="token keyword">int</span> b<span class="token operator">=</span><span class="token number">20</span><span class="token punctuation">;</span>

    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">fun</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"fun...父"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">info</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"info...父"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day14<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Zi</span> <span class="token keyword">extends</span> <span class="token class-name">Fu</span> <span class="token punctuation">{</span>
    <span class="token keyword">int</span> a<span class="token operator">=</span><span class="token number">100</span><span class="token punctuation">;</span>
    <span class="token keyword">static</span> <span class="token keyword">int</span> b<span class="token operator">=</span><span class="token number">200</span><span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">fun</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"fun...子类"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">info</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"info...子类"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day14<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TestZi</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        Fu fu <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Zi</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        fu<span class="token punctuation">.</span><span class="token function">fun</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//子类。。。</span>
      <span class="token comment" spellcheck="true">//  fu.info();//父类</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>fu<span class="token punctuation">.</span>a<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//10</span>
     <span class="token comment" spellcheck="true">//   System.out.println(fu.b);//20</span>
     <span class="token comment" spellcheck="true">// 方法看等号右边，属性看等号左边</span>

    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

</code></pre>
<p>静态。。。</p>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day14<span class="token punctuation">.</span>test02<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Demo</span> <span class="token punctuation">{</span>
    <span class="token keyword">int</span> i<span class="token punctuation">;</span>

    <span class="token keyword">static</span> Demo d1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Demo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        Demo d2<span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Demo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token function">Demo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">static</span> <span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"我是静态代码块。。。"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre>
<p>输出结果。。。<br>0<br>我是静态代码块。。。<br>0</p>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day14<span class="token punctuation">.</span>test02<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Demo02</span> <span class="token punctuation">{</span>
    <span class="token keyword">int</span> i<span class="token operator">=</span><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">"m:"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">static</span> Demo02 d1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Demo02</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        Demo02 d2<span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Demo02</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">static</span> <span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"我是静态代码块。。。"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token function">Demo02</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">print</span><span class="token punctuation">(</span>String name<span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token number">100</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="1-final关键字概述"><a href="#1-final关键字概述" class="headerlink" title="1.final关键字概述"></a>1.final关键字概述</h2><blockquote>
<p>final 最终的，final修饰的内容不可更改！</p>
<ol>
<li>final修饰的变量是常量，不可更改！作为成员变量常量全大写！</li>
</ol>
<p>成员常量，可以不直接给初始值，但是所有的构造函数必须给它初始值！</p>
<p>2.final修饰的方法不能被覆盖！</p>
<p>3.final修饰的类不能被继承！</p>
<p>4.final修饰对象，内存地址不可变！</p>
</blockquote>
<h2 id="2-类的封装"><a href="#2-类的封装" class="headerlink" title="2.类的封装"></a>2.类的封装</h2><blockquote>
<p>设计模式是为了解决问题的！</p>
<p>单例模式<br>单例：一个类只能有一个实例！ 私有化构造函数<br>饿汉模式<br>懒汉模式</p>
</blockquote>
<h3 id="1-饿汉模式"><a href="#1-饿汉模式" class="headerlink" title="[1]饿汉模式"></a>[1]饿汉模式</h3><pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day14<span class="token punctuation">.</span>singlecase<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">// 这个类只能有一个实例</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">EagerSingleTon</span> <span class="token punctuation">{</span>
<span class="token keyword">private</span> <span class="token keyword">static</span> <span class="token keyword">final</span> EagerSingleTon e<span class="token operator">=</span><span class="token keyword">new</span> <span class="token class-name">EagerSingleTon</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">//阻断一个类new对象</span>
    <span class="token keyword">private</span> <span class="token function">EagerSingleTon</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token punctuation">}</span>
    <span class="token comment" spellcheck="true">//提供get方法,让其他类获取到这个类的对象！</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> EagerSingleTon <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> e<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    
<span class="token punctuation">}</span>
</code></pre>
<h3 id="2-懒汉模式"><a href="#2-懒汉模式" class="headerlink" title="[2]懒汉模式"></a>[2]懒汉模式</h3><pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day14<span class="token punctuation">.</span>singlecase<span class="token punctuation">;</span>
<span class="token comment" spellcheck="true">//懒汉类</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">LazySingleTon</span> <span class="token punctuation">{</span>
    <span class="token keyword">private</span> <span class="token keyword">static</span> LazySingleTon e<span class="token punctuation">;</span>
    <span class="token comment" spellcheck="true">//阻断new对象</span>
    <span class="token keyword">private</span> <span class="token function">LazySingleTon</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span> <span class="token punctuation">}</span>

    <span class="token comment" spellcheck="true">//提供一个get方法让其他类可以获取对象</span>
    <span class="token keyword">public</span>  <span class="token keyword">static</span> LazySingleTon <span class="token function">getInstance</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>e<span class="token operator">==</span>null<span class="token punctuation">)</span><span class="token punctuation">{</span>
                e<span class="token operator">=</span><span class="token keyword">new</span> <span class="token class-name">LazySingleTon</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token keyword">return</span> e<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre>
<blockquote>
<p>饿汉模式   和  懒汉模式？</p>
<p>饿汉模式：不管使用还是不使用这个对象，只要用到这个类，那么就会在类加载的时候把对象创建好！<br>一旦使用这个对象，效率高，缺点，占用内存！</p>
<p>懒汉模式：使用这个对象才会创建这个对象，优点是节省内存，缺点，效率低</p>
</blockquote>
<h1 id="十三、抽象类"><a href="#十三、抽象类" class="headerlink" title="十三、抽象类"></a>十三、抽象类</h1><h2 id="1-抽象类概述"><a href="#1-抽象类概述" class="headerlink" title="1.抽象类概述"></a>1.抽象类概述</h2><p>抽象类比普通类更抽象一些，作为普通类的完善</p>
<p>在继承关系中，父类更通用（抽象），子类更具体，往往把父类描述成抽象类！</p>
<h2 id="2-抽象类语法特性"><a href="#2-抽象类语法特性" class="headerlink" title="2.抽象类语法特性"></a>2.抽象类语法特性</h2><blockquote>
<p>abstract 抽象的  关键字</p>
<p>1.abstract修饰的类是抽象类<br>  public abstract class Demo{ }</p>
<p>2.abstract修饰的方法是抽象方法，抽象方法没有方法体，只能存在于抽象类中 </p>
<p>3.有抽象方法的类一定是抽象类，抽象类不一定有抽象方法！<br>   抽象类只是比之前的类能多写抽象方法而已</p>
<p>4.抽象类不能实例化对象</p>
<p>5.抽象类的子类必须重写（实现）父类的抽象方法，除非子类也是抽象类</p>
<p>6.抽象类不能用final修饰，抽象方法不能用final修饰</p>
</blockquote>
<p>什么用抽象类？</p>
<p>通用的类，父类！</p>
<p>练习—————–</p>
<blockquote>
<p>形状类  方法：求面积</p>
<p>圆形    方法：求面积</p>
<p>长方形   方法：求面积</p>
<p>正方形   方法：求面积</p>
</blockquote>
<h1 id="十四、接口"><a href="#十四、接口" class="headerlink" title="十四、接口"></a>十四、接口</h1><h2 id="1-接口概述"><a href="#1-接口概述" class="headerlink" title="1.接口概述"></a>1.接口概述</h2><blockquote>
<p>接口，usb接口，可插拔</p>
<p>接口规范，也是定义的协议标准</p>
</blockquote>
<h2 id="2-接口语法"><a href="#2-接口语法" class="headerlink" title="2.接口语法"></a>2.接口语法</h2><blockquote>
<p>1.把类的class替换成interface就表示一个接口</p>
<p>2.接口中的成员变量是常量，默认必须用public static final修饰，可以省略不写！</p>
<p>3.接口中的方法都是默认必须用public abstract修饰，可以省略不写！</p>
<p>接口 = 常量（public static final）+抽象方法(public abstract)</p>
<p>4.接口不能被实例化对象</p>
<p>5.接口中没有构造函数</p>
<p>6.实现类实现接口必须重写接口中所有的抽象方法，除非实现类是抽象类<br>  接口和实现类的关系：  理解成继承关系，使用连接的关键字不是extends,而是implements!<br>  implements 关键字，表示类与接口的继承关系！</p>
<p>  public interface Demo{   }</p>
<p>  public class DemoImpl implements Demo{ }</p>
<p>7.一个实现类可以同时实现多个接口！</p>
<p>8.一个类可以继承一个类的同时，实现多个接口！<br>   public class B extends A implements C,D {<br>       } </p>
<p>9.接口打破单继承，一个接口可以继承多个接口！</p>
<p>public interface C extends A,B {<br>} </p>
<p>  类与类之间用extends  类与接口之间implements<br>  接口与接口之间extends </p>
<p>10.类强调的是从属关系，接口强调的是功能</p>
<p>11.接口可以使用多态！</p>
</blockquote>
<blockquote>
<p>总结：<br>1.把class变成interface<br>2.接口=常量（public static final）+抽象方法(public abstract)<br>3.接口没有构造函数也不能实例化对象<br>4.一个实现类可以实现（implements）多个接口,实现接口中所有的抽象方法，除非实现类是抽象类<br>5.一个接口可以继承多个接口<br>6.一个类可以继承一个类的同时，实现多个接口（先继承后实现！）<br>7.接口可使用多态，接口强调功能，类强调所属关系！</p>
</blockquote>
<p>设计理念不同！</p>
<p><img src="/1628822285063.png" alt="1628822285063"></p>
<p>总结接口和抽象类概念不同：</p>
<blockquote>
<p>相同：<br>1.都能写抽象方法<br>2.子类都要实现抽象方法，除非子类是抽象类<br>3.都不能实例化对象</p>
<p>不同：<br>抽象类，可以有任何变量，接口只能有常量<br>抽象类可以有非抽象方法，接口必须都是抽象方法<br>抽象类单继承，实现类可以实现多个接口，且接口能继承多个接口<br>抽象类有构造函数，接口没有构造函数<br>类强调从属关系，接口强调功能</p>
</blockquote>
<h2 id="2-1-8接口的新特性"><a href="#2-1-8接口的新特性" class="headerlink" title="2. 1.8接口的新特性"></a>2. 1.8接口的新特性</h2><pre class=" language-java"><code class="language-java">用<span class="token keyword">static</span>修饰可以写方法体
用<span class="token keyword">default</span>修饰可以写方法体

<span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day15<span class="token punctuation">.</span>test<span class="token punctuation">;</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Test</span> <span class="token punctuation">{</span>
    <span class="token keyword">static</span> <span class="token keyword">int</span> a<span class="token punctuation">;</span>
    <span class="token keyword">static</span> Test t<span class="token operator">=</span><span class="token keyword">new</span> <span class="token class-name">Test</span><span class="token punctuation">(</span><span class="token number">500</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">int</span> b<span class="token operator">=</span><span class="token function">print</span><span class="token punctuation">(</span><span class="token string">"b:"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">static</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"我是静态代码块。。。"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>t<span class="token punctuation">.</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token function">Test</span><span class="token punctuation">(</span><span class="token keyword">int</span> b<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">this</span><span class="token punctuation">.</span>b<span class="token operator">=</span>b<span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"无参构造。。。"</span><span class="token operator">+</span><span class="token punctuation">(</span><span class="token operator">++</span>a<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">print</span><span class="token punctuation">(</span>String str<span class="token punctuation">)</span><span class="token punctuation">{</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>str<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token number">100</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        Test t2 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Test</span><span class="token punctuation">(</span><span class="token number">300</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>t2<span class="token punctuation">.</span>b<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<h1 id="十五、Object类和内部类"><a href="#十五、Object类和内部类" class="headerlink" title="十五、Object类和内部类"></a>十五、Object类和内部类</h1><p>学习类就是要学习类中一些方法</p>
<p>Object类是根类</p>
<p>以下为object类的方法</p>
<h2 id="1-hashCode-方法"><a href="#1-hashCode-方法" class="headerlink" title="1.hashCode()方法"></a>1.hashCode()方法</h2><blockquote>
<p>返回值int类型<br>含义：两个对象的内存地址相对，哈希值相等，两个对象内存地址不同，哈希值不同！<br>哈希值：内存地址转换的整数，不是java实现的！</p>
<p>应用场景：<br>   哈希表（散列表）是数据结构<br>   HashMap是集合<br>   HashMap的底层原理是哈希表<br>   哈希表需要hashCode()的支持！</p>
<p>哈希冲突：不同的两个对象，不同的内存地址，相同的哈希值</p>
</blockquote>
<pre class=" language-java"><code class="language-java"><span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Student</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">hashCode</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment" spellcheck="true">//调用父类Object的方法</span>
        <span class="token keyword">return</span> <span class="token keyword">super</span><span class="token punctuation">.</span><span class="token function">hashCode</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TestStudent</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        Student s1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Student</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        Student s2 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Student</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>s1<span class="token operator">==</span>s2<span class="token punctuation">)</span><span class="token punctuation">;</span>
        System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>s1<span class="token punctuation">.</span><span class="token function">hashCode</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">==</span> s2<span class="token punctuation">.</span><span class="token function">hashCode</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<blockquote>
<p>学习一个方法： xxx()</p>
<p>1.什么含义？（查询api文档，百度，代码试一下）</p>
<p>2.为什么学？应用的场景</p>
<p>3.查看源码，怎么实现的？</p>
</blockquote>
<h2 id="2-toString-方法"><a href="#2-toString-方法" class="headerlink" title="2.toString()方法"></a>2.toString()方法</h2><pre class=" language-java"><code class="language-java">返回值 String 
含义：对象的字符串表示形式
全限定类名<span class="token operator">+</span>@<span class="token operator">+</span><span class="token number">16</span>进制（哈希值转换过来的<span class="token number">16</span>进制）
直接输出对象，跟输出对象直接调用未重写的toString（）方法是一样的！

应用场景：重写输出属性值！
以后再写javabean实例类，建议把toString一块儿生成！

源码：
   <span class="token keyword">public</span> String <span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
   <span class="token keyword">return</span> <span class="token function">getClass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">"@"</span><span class="token operator">+</span>Integer<span class="token punctuation">.</span><span class="token function">toHexString</span><span class="token punctuation">(</span>hashCode<span class="token punctuation">)</span><span class="token punctuation">;</span>
   <span class="token punctuation">}</span>
</code></pre>
<h2 id="3-equals-方法"><a href="#3-equals-方法" class="headerlink" title="3.equals()方法"></a>3.equals()方法</h2><pre class=" language-java"><code class="language-java">返回值<span class="token keyword">boolean</span>   参数Object obj

含义：object类中的equals方法比较两个对象，比较的是内存地址

作用：
  <span class="token operator">==</span> 也是可以比较对象的，equlas也是可以比较对象的  
  区别：
  <span class="token operator">==</span>既可以比较基本数据类型，也可以比较引用数据类型<span class="token punctuation">(</span>内存地址<span class="token punctuation">)</span>
  equals只能比较引用数据类型（对象）


源码：<span class="token keyword">public</span> booelan <span class="token function">equals</span><span class="token punctuation">(</span>Object obj<span class="token punctuation">)</span><span class="token punctuation">{</span>
           <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token operator">==</span>obj<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="4-内部类"><a href="#4-内部类" class="headerlink" title="4.内部类"></a>4.内部类</h2><blockquote>
<p>内部类调用外部类的成员<br>外部类调用内部类成员<br>测试类调用内部类成员</p>
</blockquote>
<ul>
<li>实例内部类</li>
</ul>
<blockquote>
<p>一个类的类体嵌套另外一个类<br>内部类直接调用外部类的成员，省略的是  外部类.this<br>外部类通过创建内部类对象调用内部类的成员<br>测试类创建对象调用内部类的成员<br> 语法：外部类.内部类 对象名 = new 外部类().new 内部类();</p>
</blockquote>
<ul>
<li>静态内部类</li>
</ul>
<blockquote>
<p>内部类只能调用外部类的静态成员！<br>外部类通过内部类类名调用内部类的静态成员，内部类类名不可省略！<br>测试类，如果调用的是内部类的静态成员，直接 外部类.内部类.成员 调用<br>如果调用的是内部类的非静态成员，创建对象调用<br>语法：外部类.内部类 对象名 = new 外部类.内部类();</p>
</blockquote>
<ul>
<li>局部内部类</li>
</ul>
<blockquote>
<p>局部内部类是在方法体中，作用域就是方法体<br>出了方法体，就不能再使用了！</p>
</blockquote>
<ul>
<li>匿名内部类</li>
</ul>
<pre><code>匿名内部类属于特殊局部内部类，存在方法中的，并且只有类体，没有名字和任何修饰！
</code></pre>
<ul>
<li>接口创建对象</li>
</ul>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day15<span class="token punctuation">.</span>inner05<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">AnimalDao</span> <span class="token punctuation">{</span>
    <span class="token keyword">void</span> <span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day15<span class="token punctuation">.</span>inner05<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">Test</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        AnimalDao dao <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">AnimalDao</span><span class="token punctuation">(</span><span class="token punctuation">)</span> 
        <span class="token comment" spellcheck="true">//匿名内部类,还是AnimalDao的实现类！</span>
        <span class="token punctuation">{</span>
            <span class="token annotation punctuation">@Override</span>
            <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"猫吃鱼。。。"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">;</span> 
        
        dao<span class="token punctuation">.</span><span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<ul>
<li>抽象类创建对象</li>
</ul>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day15<span class="token punctuation">.</span>inner06<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token keyword">class</span> <span class="token class-name">Animal</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">abstract</span> <span class="token keyword">void</span> <span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<pre class=" language-java"><code class="language-java"><span class="token keyword">package</span> cn<span class="token punctuation">.</span>bjpowernode<span class="token punctuation">.</span>javase01<span class="token punctuation">.</span>day15<span class="token punctuation">.</span>inner06<span class="token punctuation">;</span>

<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">TestAnimal</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span>String<span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        Animal a1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Animal</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token punctuation">{</span>
            <span class="token annotation punctuation">@Override</span>
            <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                System<span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"狗吃骨头。。。"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span><span class="token punctuation">;</span>

        a1<span class="token punctuation">.</span><span class="token function">eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/about" rel="external nofollow noreferrer">YangChao</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://monkey-chao.gitee.io/2022/05/06/java-ji-chu-pian-yi/">https://monkey-chao.gitee.io/2022/05/06/java-ji-chu-pian-yi/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/about" target="_blank">YangChao</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/Java/">
                                    <span class="chip bg-color">Java</span>
                                </a>
                            
                                <a href="/tags/%E6%95%99%E7%A8%8B/">
                                    <span class="chip bg-color">教程</span>
                                </a>
                            
                                <a href="/tags/%E5%9F%BA%E7%A1%80/">
                                    <span class="chip bg-color">基础</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    
    <div class="livere-card card" data-aos="fade-up">
    <!-- 来必力City版安装代码 -->
    <div id="lv-container" class="card-content" data-id="city" data-uid="">
        <script type="text/javascript">
            (function (d, s) {
                let j, e = d.getElementsByTagName(s)[0];
                if (typeof LivereTower === 'function') {
                    return;
                }

                j = d.createElement(s);
                j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
                j.async = true;

                e.parentNode.insertBefore(j, e);
            })(document, 'script');
        </script>
        <noscript>为正常使用来必力评论功能请激活JavaScript。</noscript>
    </div>
    <!-- City版安装代码已完成 -->
</div>
    

    
        <style>
    .valine-card {
        margin: 1.5rem auto;
    }

    .valine-card .card-content {
        padding: 20px 20px 5px 20px;
    }

    #vcomments textarea {
        box-sizing: border-box;
        background: url("/medias/comment_bg.png") 100% 100% no-repeat;
    }

    #vcomments p {
        margin: 2px 2px 10px;
        font-size: 1.05rem;
        line-height: 1.78rem;
    }

    #vcomments blockquote p {
        text-indent: 0.2rem;
    }

    #vcomments a {
        padding: 0 2px;
        color: #4cbf30;
        font-weight: 500;
        text-decoration: none;
    }

    #vcomments img {
        max-width: 100%;
        height: auto;
        cursor: pointer;
    }

    #vcomments ol li {
        list-style-type: decimal;
    }

    #vcomments ol,
    ul {
        display: block;
        padding-left: 2em;
        word-spacing: 0.05rem;
    }

    #vcomments ul li,
    ol li {
        display: list-item;
        line-height: 1.8rem;
        font-size: 1rem;
    }

    #vcomments ul li {
        list-style-type: disc;
    }

    #vcomments ul ul li {
        list-style-type: circle;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    #vcomments table, th, td {
        border: 0;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments h1 {
        font-size: 1.85rem;
        font-weight: bold;
        line-height: 2.2rem;
    }

    #vcomments h2 {
        font-size: 1.65rem;
        font-weight: bold;
        line-height: 1.9rem;
    }

    #vcomments h3 {
        font-size: 1.45rem;
        font-weight: bold;
        line-height: 1.7rem;
    }

    #vcomments h4 {
        font-size: 1.25rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    #vcomments h5 {
        font-size: 1.1rem;
        font-weight: bold;
        line-height: 1.4rem;
    }

    #vcomments h6 {
        font-size: 1rem;
        line-height: 1.3rem;
    }

    #vcomments p {
        font-size: 1rem;
        line-height: 1.5rem;
    }

    #vcomments hr {
        margin: 12px 0;
        border: 0;
        border-top: 1px solid #ccc;
    }

    #vcomments blockquote {
        margin: 15px 0;
        border-left: 5px solid #42b983;
        padding: 1rem 0.8rem 0.3rem 0.8rem;
        color: #666;
        background-color: rgba(66, 185, 131, .1);
    }

    #vcomments pre {
        font-family: monospace, monospace;
        padding: 1.2em;
        margin: .5em 0;
        background: #272822;
        overflow: auto;
        border-radius: 0.3em;
        tab-size: 4;
    }

    #vcomments code {
        font-family: monospace, monospace;
        padding: 1px 3px;
        font-size: 0.92rem;
        color: #e96900;
        background-color: #f8f8f8;
        border-radius: 2px;
    }

    #vcomments pre code {
        font-family: monospace, monospace;
        padding: 0;
        color: #e8eaf6;
        background-color: #272822;
    }

    #vcomments pre[class*="language-"] {
        padding: 1.2em;
        margin: .5em 0;
    }

    #vcomments code[class*="language-"],
    pre[class*="language-"] {
        color: #e8eaf6;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }

    #vcomments b,
    strong {
        font-weight: bold;
    }

    #vcomments dfn {
        font-style: italic;
    }

    #vcomments small {
        font-size: 85%;
    }

    #vcomments cite {
        font-style: normal;
    }

    #vcomments mark {
        background-color: #fcf8e3;
        padding: .2em;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }
</style>

<div class="card valine-card" data-aos="fade-up">
    <div class="comment_headling" style="font-size: 20px; font-weight: 700; position: relative; padding-left: 20px; top: 15px; padding-bottom: 5px;">
        <i class="fas fa-comments fa-fw" aria-hidden="true"></i>
        <span>评论</span>
    </div>
    <div id="vcomments" class="card-content" style="display: grid">
    </div>
</div>

<script src="/libs/valine/av-min.js"></script>
<script src="/libs/valine/Valine.min.js"></script>
<script>
    new Valine({
        el: '#vcomments',
        appId: '1543373971',
        appKey: '111111',
        notify: 'false' === 'true',
        verify: 'false' === 'true',
        visitor: 'true' === 'true',
        avatar: 'mm',
        pageSize: '10',
        lang: 'zh-cn',
        placeholder: 'just go go'
    });
</script>

<!--酷Q推送-->


    

    
        <style>
    .mvaline-card {
        margin: 1.5rem auto;
    }

    .mvaline-card .card-content {
        padding: 20px 20px 5px 20px;
    }
</style>

<div class="card mvaline-card" data-aos="fade-up">
    <div class="comment_headling" style="font-size: 20px; font-weight: 700; position: relative; padding-left: 20px; top: 15px; padding-bottom: 5px;">
        <i class="fas fa-comments fa-fw" aria-hidden="true"></i>
        <span>评论</span>
    </div>
    <div id="mvcomments" class="card-content" style="display: grid">
    </div>
</div>

<script src="/libs/minivaline/MiniValine.js"></script>
<script>
    new MiniValine(Object.assign({"enable":true,"serverURL":"https://minivaline.your-domain.top"}, {
	  el: '#mvcomments',
    }));
</script>

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2022/05/07/linux-chang-yong-ming-ling/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/19.jpg" class="responsive-img" alt="Linux常用命令">
                        
                        <span class="card-title">Linux常用命令</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            Linux常用命令介绍
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2022-05-07
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/" class="post-category">
                                    开发环境
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/%E9%9D%A2%E8%AF%95/">
                        <span class="chip bg-color">面试</span>
                    </a>
                    
                    <a href="/tags/Linux/">
                        <span class="chip bg-color">Linux</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2022/05/05/java-mian-shi-ti-ji-wang-pian/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/9.jpg" class="responsive-img" alt="Java面试题（计网篇）">
                        
                        <span class="card-title">Java面试题（计网篇）</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            Java面试题（计网篇）详解
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2022-05-05
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/" class="post-category">
                                    计算机网络
                                </a>
                            
                            <a href="/categories/%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/%E9%9D%A2%E8%AF%95%E5%AE%9D%E5%85%B8/" class="post-category">
                                    面试宝典
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/%E9%9D%A2%E8%AF%95/">
                        <span class="chip bg-color">面试</span>
                    </a>
                    
                    <a href="/tags/%E7%BD%91%E7%BB%9C%E5%8D%8F%E8%AE%AE/">
                        <span class="chip bg-color">网络协议</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('120')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE' || selection.getRangeAt(0).commonAncestorContainer.nodeName === 'CODE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + '来源: Angus<br />'
            + '文章作者: YangChao<br />'
            + '文章链接: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {bodyElement.removeChild(newdiv);}, 200);
    });
</script>


<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    

    <div class="container row center-align"
         style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2019-2023</span>
            
            <a href="/about" target="_blank">YangChao</a>
<!--             |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/Monkey-chao/Monkey-chao.github.io.git" target="_blank">Matery</a> -->
            <br>
            
                &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                        class="white-color">460.9k</span>
            
            
            
                
            
            
                <span id="busuanzi_container_site_pv">
                &nbsp;|&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;
                    <span id="busuanzi_value_site_pv" class="white-color"></span>
            </span>
            
            
                <span id="busuanzi_container_site_uv">
                &nbsp;|&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;
                    <span id="busuanzi_value_site_uv" class="white-color"></span>
            </span>
            
            <br>

            <!-- 运行天数提醒. -->
            
            <br>
            
        </div>
<!--         <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/Monkey-chao/Monkey-chao.github.io.git" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>




<!-- 

 -->


    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=1543373971" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 1543373971" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>


<!-- 




    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

 --></div>
 -->     </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    

    
        
        <script type="text/javascript">
            // 只在桌面版网页启用特效
            var windowWidth = $(window).width();
            if (windowWidth > 768) {
                document.write('<script type="text/javascript" src="/libs/others/sakura.js"><\/script>');
            }
        </script>
    

    <!-- 雪花特效 -->
    

    <!-- 鼠标星星特效 -->
    

    

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    <!--腾讯兔小巢-->
    
    

    

    

    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
